package servlet;

import util.Linksql;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class AnnDelet extends HttpServlet {
    int id=0;
    Connection con=null;
    PreparedStatement pre=null;
    String sql="delete from announcement where announcement_num="+"?";
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            id= Integer.parseInt(request.getParameter("id"));
            con= Linksql.getConnection();
            pre=con.prepareStatement(sql);
            pre.setInt(1,id);
            pre.executeUpdate();
            pre.close();
            con.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
